package com.onedec.designer.service.impl;

import com.onedec.designer.entity.OnedecConstruction;
import com.onedec.designer.entity.OnedecConstructionExample;
import com.onedec.designer.entity.OnedecPlan;
import com.onedec.designer.entity.OnedecPlanExample;
import com.onedec.designer.mapper.OnedecConstructionMapper;
import com.onedec.designer.mapper.OnedecPlanMapper;
import com.onedec.designer.service.OnedecConstructionService;
import com.onedec.designer.service.OnedecPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OnedecConstructionServiceImpl implements OnedecConstructionService {
    @Autowired
    private OnedecConstructionMapper onedecConstructionMapper;


    @Override
    public List<Map<String, Object>> selectByMap(Map<String, Object> map) {
        return onedecConstructionMapper.selectByMap(map);
    }

    @Override
    public long accountnum() {
        return onedecConstructionMapper.countByExample(null);
    }

    @Override
    public void deleteById(int id) {
        onedecConstructionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertOne(OnedecConstruction onedecConstruction) {
        onedecConstructionMapper.insertSelective(onedecConstruction);
    }


    @Override
    public OnedecConstruction selectById(int id) {
        return onedecConstructionMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(OnedecConstruction onedecConstruction) {
        onedecConstructionMapper.updateByPrimaryKeySelective(onedecConstruction);
    }

    @Override
    public void updateById(int id) {
        OnedecConstruction onedecConstruction = onedecConstructionMapper.selectByPrimaryKey(id);
        onedecConstruction.setConstructionStatus("1");
        onedecConstructionMapper.updateByPrimaryKeySelective(onedecConstruction);
    }

    @Override
    public void rejectById(int id) {
        OnedecConstruction onedecConstruction = onedecConstructionMapper.selectByPrimaryKey(id);
        onedecConstruction.setConstructionStatus("3");
        onedecConstructionMapper.updateByPrimaryKeySelective(onedecConstruction);
    }

    @Override
    public List<OnedecConstruction> selectByProjectId(int id) {
        OnedecConstructionExample onedecConstructionExample = new OnedecConstructionExample();

        OnedecConstructionExample.Criteria or = onedecConstructionExample.or();
        or.andConstructionProjectIdEqualTo(id);

        return onedecConstructionMapper.selectByExample(onedecConstructionExample);
    }
}
